package com.kedou.sdk.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.kedou.sdk.ui.assist.OnFinishActivityListener;
import com.kedou.sdk.utils.WL;

/**
 * Created by Administrator on 2018/3/8.
 */

public class CreateXiaohaoFragment extends BaseDialogFragment implements View.OnClickListener {



    private Button mconfirmEvent;
    private EditText inptuEdit;
    private ImageButton backImage;

    public static final CreateXiaohaoFragment newInstance(Bundle bundle) {
        CreateXiaohaoFragment fragment = new CreateXiaohaoFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View contentView = doInflateContentView(inflater, container, getLayoutIdentifier("hnssn_fragment_createxiaohao"));
        WL.e("NoticeTipDialogFragment","NoticeTipDialogFragment");

        mconfirmEvent = contentView.findViewById(getViewIdentifier("activity_login_submit_btn"));
        inptuEdit = contentView.findViewById(getViewIdentifier("activity_login_account_et"));
        backImage = contentView.findViewById(getViewIdentifier("activity_login_finish_btn"));
        backImage.setOnClickListener(this);
        mconfirmEvent.setOnClickListener(this);
        inptuEdit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                mconfirmEvent.setEnabled(TextUtils.isEmpty(editable.toString())?false:true);
            }
        });
        return contentView;
    }



    @Override
    public void onClick(View view) {
        if (view==backImage){
            OnUserLoginActionListener listener = getOnFinishActivityListener();
            if (listener != null) {
                listener.doFinishActivity(this);
            }
        }else if(view==mconfirmEvent){
            OnUserLoginActionListener listener = getOnFinishActivityListener();
            if (listener != null) {
                listener.doCreateSmallAccount(inptuEdit.getText().toString().trim());
            }
        }

    }

    private OnUserLoginActionListener getOnFinishActivityListener() {
        if (!isNullContext()) {
            Activity activity = getActivity();
            if (activity instanceof OnUserLoginActionListener) {
                return (OnUserLoginActionListener) activity;
            }
        }
        return null;
    }

    public interface OnUserLoginActionListener extends OnFinishActivityListener {

        void doCreateSmallAccount(String username);
    }
}
